<?php
header('Content-type:text/html;charset=utf-8');
session_start();
include_once 'dbconfig.php';
include_once 'common.php';

if ($_POST) {
    if (isset($_POST['postType']) && $_POST['postType'] == 'login') {
        $name = $_POST['name'];
        $psw = md5($_POST['psw']);
        $selectSql = 'select psw from user where userName = "' . $name . '"';
        $res = $link->query($selectSql);
        if ($res->num_rows > 0) {
            $arr = [];
            while ($row = $res->fetch_assoc()) {
                array_push($arr, $row);
            }
            if ($psw === $arr[0]['psw']) {
                $msg = ['msg' => '登录成功', 'status' => 1];
                $_SESSION['loginUserName'] = $name;
            } else {
                $msg = ['msg' => '登录失败，密码错误', 'status' => 0];
            }
            responseEvent($msg);
        } else {
            $msg = ['msg' => '“' . $name . '”未注册', 'status => 0'];
            responseEvent($msg);
        }
    }
}


